<template>
  <div>
    <head-text titleText="案件回收"></head-text>
    <div class="list-content">
      <div class="filter-area">
        <Search :searchData="searchData" :searchItem="searchItem"></Search>
      </div>
      <div class="table-title">
        <h5>案件回收</h5>
      </div>
      <custom-table
        :tableData="tableData"
        :tableListData="tableListData"
        :tableBtn="tableBtn"
        :currentData="currentData"
        @handleRecovery="handleRecovery"
        @onPageChange="onPageChange"
        @onSizeChange="onSizeChange"
      ></custom-table>
    </div>
  </div>
</template>

<script>
import headText from "@c/headText";
import customTable from "@c/table";
import Search from "@c/search";
import {
  APPLYSTATUSENUM,
  APPLYCATEGORYENUM,
  APPLYTYPEENUM
} from "@u/wordbook";
import { getApplyManagePageApi, getrevertCaseListURLApi, getSysuserSelectApi } from "@s/api";

export default {
  components: {
    headText,
    customTable,
    Search
  },
  data() {
    return {
      searchItem: [],
      searchData: {
        uid: "",
        name: "",
        customerName: undefined,
        agentId: undefined,
        deleter: undefined,
        updateTimeStart: undefined,
        updateTimeEnd: undefined
      },
      pageNo: 1,
      total: 0,
      pageSize: 10,
      currentData: {},
      tableData: [],
      isAgent: [] // 代理人
    };
  },
  created() {
    this.searchItem = [
      {
        type: "input",
        label: "案件名：",
        prop: "name",
        placeholder: "请输入"
      },
      {
        type: "input",
        label: "客户：",
        prop: "customerName",
        placeholder: "请输入"
      },
      {
        type: "select",
        label: "代理人：",
        prop: "agentId",
        placeholder: "请选择",
        selectList: this.isAgent
      },
      {
        type: "input",
        label: "删除人：",
        prop: "deleter",
        placeholder: "请输入"
      },
      {
        type: "daterange",
        label: "删除日期：",
        timeFormat: "yyyy-MM-dd",
        timeList: ["updateTimeStart", "updateTimeEnd"]
      }
    ];
    //  table表格
    this.tableListData = [
      { width: "50", label: "", type: "index" },
      { prop: "customerName", width: "200px", label: "客户名称", type: "a" },
      { prop: "orderNumber", width: "160px", label: "案卷号", type: "a" },
      {
        prop: "applyCategory",
        width: "90px",
        label: "分类",
        type: "wordbook",
        wordbookList: this.getApplyCategory
      },
      {
        prop: "applyType",
        width: "90px",
        label: "类型",
        type: "wordbook",
        wordbookList: this.getApplyType
      },
      { prop: "title", width: "230px", label: "申请名称" },
      { prop: "agentName", width: "90px", label: "代理人" },
      { prop: "applyNumber", width: "150px", label: "申请号" },
      { prop: "applyDatetime", width: "150px", label: "申请日期" },
      {
        prop: "status",
        width: "130px",
        label: "状态",
        type: "wordbook",
        wordbookList: this.getApplyStatus
      },
      { prop: "fileNames", width: "500px", label: "已上传文件", type: "a" },
      { prop: "deleter", width: "150px", label: "删除人" },
      { prop: "updateTime", width: "150px", type: "date", label: "删除日期" },
      { label: "操作", type: "btn", width: "150", fixed: "right" }
    ]
    // 按钮
    this.tableBtn = [
      {
        name: "恢复",
        btnType: "primary",
        handleFn: "handleRecovery"
      }
    ];
  },
  mounted() {
    this.getList();
    this.getSysuserSelect();
  },
  methods: {
    //获取列表
    getList() {
      let json = JSON.parse(JSON.stringify(this.searchData));
      json.pageNo = this.pageNo;
      json.isDelete = 1;
      json.pageSize = this.pageSize;
      getApplyManagePageApi(json).then(res => {
        this.tableData = res.list;
        this.currentData.total = res.total;
      });
    },
     // 代理人
    getSysuserSelect() {
      getSysuserSelectApi({ name: "代理人" }).then((res) => {
       let newisAgentList = [];
        res.forEach(item => {
          var newItem = {
            id: item.userId,
            value: item.userName
          };
          newisAgentList.push(newItem);
        });
        this.isAgent = newisAgentList;
        this.searchItem.forEach(item => {
          if (item.prop == "agentId") {
            item.selectList = this.isAgent;
          }
        });
      });
    },
     getApplyCategory(val) {
      return APPLYCATEGORYENUM[val];
    },
    getApplyType(val) {
      return APPLYTYPEENUM[val];
    },
    getApplyStatus(val) {
      return APPLYSTATUSENUM[val];
    },
    onPageChange(val) {
      this.pageNo = val;
      this.getList();
    },
    onSizeChange(val) {
      this.pageNo = 1;
      this.pageSize = val;
      this.getList();
    },
    // 搜索事件
    getDataList(val) {
      this.searchData = val;
      this.pageNo = 1;
      this.pageSize = 10;
      this.$nextTick(() => {
        this.getList();
      });
    },
    // 恢复案件
    async handleRecovery(row) {
      const res = await getrevertCaseListURLApi([row.id]);
      this.$message({
        type: "success",
        message: res
      });
      this.getList();
    }
  }
};
</script>

<style lang="scss" scoped></style>
